package com.lagou.code.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.lagou.dubbo.CodeDubbo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;

@Service
public class CodeDubboImpl implements CodeDubbo {
    @Autowired
    private RedisTemplate<Object,Object> redisTemplate;

    @Override
    public int validate(String email, String code) {
        //校验验证码是否正确
        //0正确1错误2超时
        if(redisTemplate.opsForValue().get("code:"+email) == null){
            return 2;
        }
        String rightCode = redisTemplate.opsForValue().get("code:" + email).toString();
        if(code.equalsIgnoreCase(rightCode)){
            return 0;
        }
        return 1;
    }
}
